<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <title>Title</title>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="#">管理员管理</a>
                    </div>

                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                            <li class="active"><a href="/tp.do?key=LoginTask.home">用户管理</a></li>
                            <li><a href="/tp.do?key=AdminTclass.home">班级管理</a></li>
                            <li><a href="/tp.do?key=CourseTask.home">课程管理</a></li>
                            <li><a href="/tp.do?key=AdminSys.home">日志管理</a></li>
                        </ul>

                        <ul class="nav navbar-nav navbar-right">
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">欢迎您，${loginUser.name}<span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="/tp.do?key=LoginTask.logout">退出</a></li>
                                </ul>
                            </li>
                        </ul>
                    </div><!-- /.navbar-collapse -->
                </div><!-- /.container-fluid -->
            </nav>

        </div>
    </div>
    <div class="row">
        <div class="col-md-8">
            <form class="form-inline" role="form" method="post" action="tp.do" id="form_search">
            <label>类别:</label>
           <select class="form-control" style="width:105px" id="type" name="type">
               <option value="0">全部</option>
               <option value="50">教师</option>
               <option value="1">学生</option>
               <option value="70">班主任</option>
           </select>
            <div class="form-group">
                <label>用户名:</label>
                <input type="text" class="form-control" id="usename" name="username" style="width:120px" >
            </div>
                <input type="hidden" name="key" value="AdminTask.home">
            <button type="submit" class="btn btn-default" id="sera">搜索</button>
            </form>
        </div>
        <div class="col-md-4">
            <button class="btn btn-success" id="addbtn">新增</button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover" id="tbd">
                <thead>
                <tr>
                    <td>#</td>
                    <td>身份</td>
                    <td>编号</td>
                    <td>姓名</td>
                    <td>电话</td>
                    <td>邮箱</td>
                    <td>用户名</td>
                </tr>
                </thead>
                <tbody>
                <#list members as member>
                <tr>
                    <td>${member.id}</td>
                    <td>
                        <#if  member.type==1>
                        学生
                        <#elseif  member.type==99>
                        管理员
                        <#elseif  member.type==50>
                        教师
                        <#elseif  member.type==70>
                        班主任
                        <#else>
                        白板
                        </#if>
                    </td>
                    <td>${member.code}</td>
                    <td>${member.name}</td>
                    <td>${member.tel}</td>
                    <td>${member.email}</td>
                    <td>${member.username}</td>
                    <td><button type="button" class="btn btn-success"><span class="glyphicon glyphicon-pencil edit_btn" onclick="editbut(${member.id})">编辑</span></button>
                        <button class="btn btn-danger"><span class="glyphicon glyphicon-trash del_btn" onclick="delbut(${member.id})">删除</span></button>
                    </td>

                </tr>
                </#list>
                </tbody>
            </table>
        </div>
    </div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <form>
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">增加用户</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">身份</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="usetype" name="type">
                                <option value="1">学生</option>
                                <option value="50">教师</option>
                                <option value="70">班主任</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">编号</label>
                        <div class="col-sm-10">
                            <input type="number" name="code" class="form-control" placeholder="编号">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">name</label>
                        <div class="col-sm-10">
                            <input type="text" name="name" class="form-control" id="name" placeholder="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">tel</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="tel" placeholder="name" name="tel">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
                        <div class="col-sm-10">
                            <input type="email" class="form-control" id="inputEmail3" placeholder="Email" name="email">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="username" placeholder="name" name="username">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="inputPassword3" placeholder="Password" name="password">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="addbutt">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
        </form>
    </div><!-- /.modal -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="editeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">编号</label>
                        <div class="col-sm-10">
                            <p class="form-control-static" id="userid" name="userid"></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">username</label>
                        <div class="col-sm-10">
                            <p class="form-control-static" id="etusername">email@example.com</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
                        <div class="col-sm-10">
                            <input type="email" class="form-control"  id="upemail" placeholder="Email" name="upemail">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">tel</label>
                        <div class="col-sm-10">
                            <input type="email" class="form-control"  placeholder="text" name="uptel" id="uptel">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control"  placeholder="Password" name="uppassword">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="et_but">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
<script>
    //添加按钮点击事件
$("#addbtn").click(function () {
    $("#myModal").modal({
        backdrop:false
    });
});
//添加模态框保存
$("#addbutt").click(function () {

    $.ajax({
        url:"/tp.do?key=AdminTask.save",
        type:"get",
        data:$("#myModal form").serialize(),
        success:function (result) {
            $("#myModal").modal("hide");
        }
    });
});
function editbut(id) {
    getuser(id);
    $("#editeModal").modal({
        backdrop:false
    });

}
    function delbut(id) {
        if (confirm("删除别后悔!!!!")){

            $.ajax({
                url:"/tp.do?key=AdminTask.del",
                type:"post",
                data:"id="+id,
                success:function (result) {
                    //alert(result.msg);
                }
            });
        }
    }
function getuser(id) {
    $.ajax({
        url:"/tp.do",
        type:"post",
        data:"key=AdminTask.finduser&id="+id,
        success:function (result) {
            var user= result.user;
            $("#userid").text(user.id);
            $("#etusername").text(user.username);
            $("#upemail").val(user.email);
            $("#uptel").val(user.tel);



        }
    });
}
    //更改模态框保存
    $("#et_but").click(function () {

        $.ajax({
            url:"/tp.do?key=AdminTask.update",
            type:"post",
            data:"userid="+$("#userid").text()+"&"+$("#editeModal form").serialize(),
            success:function (result) {
                $("#editeModal").modal("hide");
            }
        });
    });
$("#sera").click(function () {
// var type = $("#type").val();
// var username = $("#usename").val();
//

});
</script>
</html>